home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / drivers / nics / pktdrv7 / pktsend.asm < prev    next >
Encoding:
Assembly Source File  |  1990-07-24  |  8.6 KB  |  413 lines

  1. version    equ    0
  2.  
  3. ;  Russell Nelson, Clarkson University.  December 24, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30. copyleft_msg    label    byte
  31.  db "Packet sender version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?
  44. handle        dw    ?
  45. repeat_switch    db    ?
  46. quiet_switch    db    ?
  47. async_switch    db    ?
  48.  
  49. send_count    dw    ?,?
  50. pkt_count    dd    ?
  51.  
  52. async_iocb1    iocb    <0, 0, DONE>    ;Two iocbs
  53. async_iocb2    iocb    <0, 0, DONE>
  54.  
  55. signature    db    'PKT DRVR',0
  56. signature_len    equ    $-signature
  57.  
  58. no_signature_msg    db    "No packet driver at that address",'$'
  59. usage_msg    db    "usage: pktsend <packet_int_no> [-r [-q] | -n number] [-f filename | -l length | packet]",'$'
  60. sending_msg    label    byte
  61.     db    "Press space to re-send packet(s).  Any other key exits.",CR,LF,'$'
  62. repeat_msg    label    byte
  63.     db    "Sending repeat packets.  Any key exits.",CR,LF,'$'
  64. file_not_found    db    "File not found",'$'
  65. read_trouble    db    "Trouble reading the file",'$'
  66. non_number_msg    db    "Non-numeric input found",'$'
  67. mem_trashed_msg    db    "Found trashed memory",'$'
  68.  
  69. line_buffer    db    128 dup(?)
  70.  
  71. usage_error:
  72.     mov    dx,offset usage_msg
  73. error:
  74.     mov    ah,9
  75.     int    21h
  76.     int    20h
  77.  
  78. start_1:
  79.     mov    dx,offset copyleft_msg
  80.     mov    ah,9
  81.     int    21h
  82.  
  83.     mov    si,offset phd_dioa+1
  84.     cmp    byte ptr [si],CR    ;end of line?
  85.     je    usage_error
  86.  
  87.     mov    di,offset packet_int_no
  88.     call    get_number
  89.     mov    word ptr pkt_count,1
  90.     mov    word ptr pkt_count+2,0
  91.  
  92. another_switch:
  93.     call    skip_blanks
  94.  
  95.     mov    al,[si]            ;did the give the packet inline?
  96.     cmp    al,'-'            ;did they specify a switch?
  97.     jne    not_switch
  98.     cmp    byte ptr [si+1],'r'    ;did they specify '-r'?
  99.     je    got_repeat_switch
  100.     cmp    byte ptr [si+1],'q'    ;did they specify '-q'?
  101.     je    got_quiet_switch
  102.     cmp    byte ptr [si+1],'n'    ;did they specify '-n'?
  103.     je    got_number_switch
  104.     cmp    byte ptr [si+1],'l'    ;did they specify '-l'?
  105.     je    got_length_switch
  106.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  107.     je    start_file
  108.     cmp    byte ptr [si+1],'a'    ;did they specify '-a'?
  109.     je    got_async_switch
  110.     jmp    usage_error        ;no, must be an error.
  111. got_repeat_switch:
  112.     mov    repeat_switch,1
  113.     add    si,2
  114.     jmp    another_switch
  115. got_quiet_switch:
  116.     mov    quiet_switch,1
  117.     add    si,2
  118.     jmp    another_switch
  119. got_number_switch:
  120.     add    si,2
  121.     mov    di,offset pkt_count
  122.     call    get_number
  123.     jmp    another_switch
  124. got_length_switch:
  125.     add    si,2
  126.     mov    di,offset send_count
  127.     call    get_number
  128.     mov    di,offset our_buffer
  129.     add    di,send_count
  130.     jmp    start_gotit
  131. got_async_switch:
  132.     mov    async_switch,1
  133.     add    si,2
  134.     jmp    another_switch
  135. not_switch:
  136.     jmp    start_inline        ;yes.
  137.  
  138. start_file:
  139.     add    si,2
  140.     call    skip_blanks
  141.     mov    dx,si            ;remember where the filename starts.
  142. start_3:
  143.     lodsb
  144.     cmp    al,' '
  145.     je    start_4
  146.     cmp    al,CR
  147.     jne    start_3
  148. start_4:
  149.     dec    si
  150.     mov    byte ptr [si],0
  151.  
  152. ;read the packet bytes from the named file.
  153.  
  154.     mov    ax,3d00h        ;open for reading.
  155.     int    21h
  156.     jnc    file_found
  157.     mov    dx,offset file_not_found
  158.     jmp    error
  159.  
  160. file_found:
  161.     mov    handle,ax
  162.     mov    di,offset our_buffer
  163. start_line:
  164.     mov    si,offset line_buffer
  165. again_line:
  166.     mov    ah,3fh            ;read a single character.
  167.     mov    bx,handle
  168.     mov    cx,1
  169.     mov    dx,si
  170.     int    21h
  171.     jnc    no_trouble
  172.     mov    dx,offset read_trouble
  173.     jmp    error
  174.  
  175. no_trouble:
  176.     cmp    ax,1            ;did we actually read one?
  177.     je    not_eof
  178.     cmp    si,offset line_buffer    ;did we read anything this time?
  179.     je    start_file_eof        ;no, it's really eof this time.
  180.     mov    [si],byte ptr CR    ;add an extra CR, just in case.
  181.     jmp    short done_reading
  182. not_eof:
  183.     lodsb                ;get the character we just read.
  184.     cmp    al,LF            ;got the LF?
  185.     jne    again_line        ;no, read again.
  186.  
  187. done_reading:
  188.     mov    si,offset line_buffer
  189. again_chars:
  190.     call    get_number
  191.     jnc    got_a_number
  192.     mov    dx,offset non_number_msg
  193.     jmp    error
  194. got_a_number:
  195.     inc    di
  196.     call    skip_blanks
  197.     cmp    al,CR
  198.     jne    again_chars        ;keep going to the end.
  199.  
  200.     jmp    start_line
  201.  
  202. start_file_eof:
  203.     mov    ah,3eh            ;close the file.
  204.     mov    bx,handle
  205.     int    21h
  206.     jmp    short start_gotit
  207.  
  208. start_inline:
  209. ;read the packet bytes off the command line.
  210.     mov    di,offset our_buffer-1
  211. start_2:
  212.     inc    di            ;pre-increment
  213.     call    get_number        ;get a byte.
  214.     jnc    start_2            ;keep going to the end.
  215.  
  216. start_gotit:
  217.  
  218.     sub    di,offset our_buffer
  219.     mov    send_count,di
  220.  
  221.     mov    sp,offset start        ;now that we're finished with
  222.                     ;the parameters, put our stack there.
  223.  
  224.     mov    di,offset our_buffer + GIANT * 2
  225.     inc    di
  226.     and    di,not 1
  227.     push    cs
  228.     pop    es
  229. init_memory:
  230.     mov    ax,055aah        ;initialize a segment to 055aah.
  231.     mov    cx,di
  232.     neg    cx
  233.     shr    cx,1
  234.     stosw
  235.     sub    cx,2
  236.     rep    stosw
  237.     mov    ax,es
  238.     add    ax,1000h
  239.     mov    es,ax
  240.     cmp    ax,9000h        ;don't go past 9000h.
  241.     jbe    init_memory
  242.  
  243.     mov    ah,35h            ;get their packet interrupt.
  244.     mov    al,packet_int_no
  245.     int    21h
  246.     mov    their_isr.offs,bx
  247.     mov    their_isr.segm,es
  248.  
  249.     lea    di,3[bx]
  250.     mov    si,offset signature
  251.     mov    cx,signature_len
  252.     repe    cmpsb
  253.     je    signature_ok
  254.     jmp    no_signature_err
  255. signature_ok:
  256.  
  257.     push    ds
  258.     mov    ax,1ffh            ;driver_info
  259.     int_pkt
  260.     pop    ds
  261.     call    fatal_error
  262.  
  263.     mov    ah,2            ;access all packets.
  264.     mov    al,ch            ;their class from driver_info().
  265.     mov    bx,dx            ;their type from driver_info().
  266.     mov    dl,cl            ;their number from driver_info().
  267.     mov    cx,0            ;type length of zero.
  268.     push    cs            ;es:di -> our receiver.
  269.     pop    es
  270.     mov    di,offset our_recv
  271.     int_pkt
  272.     call    fatal_error
  273.     mov    handle,ax
  274.  
  275.     cmp    repeat_switch,0
  276.     je    load_count
  277.     mov    dx,offset repeat_msg
  278.     mov    ah,9
  279.     int    21h
  280. load_count:
  281.     mov    ax,word ptr pkt_count
  282.     mov    dx,word ptr pkt_count+2
  283.  
  284. wait_for_key:
  285.     push    ax
  286.     push    dx
  287.     mov    ah,4            ;send_pkt
  288.     mov    si,offset our_buffer    ;ds:si -> buffer.
  289.     mov    cx,send_count
  290.     cmp    async_switch,0        ;async?
  291.     je    send_pkt        ;no
  292.     mov    ah,12            ;as_send_pkt
  293. find_iocb:                ;find a free iocb
  294.     mov    di,offset async_iocb1    ;try first
  295.     test    [di].flags,DONE        ;free?
  296.     jnz    got_iocb        ;yes
  297.     mov    di,offset async_iocb2    ;no, try second
  298.     test    [di].flags,DONE        ;free?
  299.     jz    find_iocb        ;no, try first again
  300. got_iocb:                ;set up iocb
  301.     mov    word ptr [di].buffer,si
  302.     mov    word ptr [di].buffer+2,ds
  303.     mov    es,word ptr [di].buffer+2
  304.     mov    [di].len,cx
  305.     mov    [di].flags,0        ;clear flags (i.e. DONE bit)
  306. send_pkt:
  307.     int_pkt
  308.     jc    pkt_bad
  309.     pop    dx
  310.     pop    ax
  311.     sub    ax,1            ;decrement low word
  312.     sbb    dx,0            ;decrement high word
  313.     mov    bx,ax            ;check if we reached zero
  314.     or    bx,dx
  315.     jne    wait_for_key        ;we didn't
  316.  
  317. check_repeat:
  318.     cmp    repeat_switch,0        ;did they ask for repeat sending?
  319.     jne    send_repeat
  320.  
  321.     mov    dx,offset sending_msg
  322.     mov    ah,9
  323.     int    21h
  324.  
  325.     mov    ah,0            ;read a key.
  326.     int    16h
  327.     cmp    al,' '
  328.     je    load_count        ;a space -- send again.
  329.     jmp    short send_done
  330.  
  331. send_repeat:
  332.     cmp    quiet_switch,0
  333.     jne    chrout_done
  334.     mov    al,'.'
  335.     call    chrout
  336.  
  337. chrout_done:
  338.     mov    ah,1            ;check for any key.
  339.     int    16h
  340.     mov    ax,word ptr pkt_count
  341.     mov    dx,word ptr pkt_count+2
  342.     je    wait_for_key        ;no key -- keep waiting.
  343.  
  344.     mov    ah,0            ;read a key.
  345.     int    16h
  346.  
  347. send_done:
  348.     mov    ah,3            ;release the handle.
  349.     mov    bx,handle
  350.     int_pkt
  351.     call    fatal_error
  352.  
  353.     mov    di,offset our_buffer + GIANT * 2
  354.     inc    di
  355.     and    di,not 1
  356.     push    cs
  357.     pop    es
  358. compare_memory:
  359.     mov    ax,055aah        ;compare a segment against 055aah.
  360.     mov    cx,di
  361.     neg    cx
  362.     shr    cx,1
  363.     scasw
  364.     jne    memory_bad
  365.     sub    cx,2
  366.     repe    scasw
  367.     jne    memory_bad
  368.     mov    ax,es
  369.     add    ax,1000h
  370.     mov    es,ax
  371.     cmp    ax,9000h        ;don't go past 9000h.
  372.     jbe    compare_memory
  373.  
  374.     int    20h
  375. pkt_bad:
  376.     call    print_error
  377.     int    20h
  378.  
  379. memory_bad:
  380.     mov    dx,offset mem_trashed_msg
  381.     mov    ah,9
  382.     int    21h
  383.     int    20h
  384.  
  385. no_signature_err:
  386.     mov    dx,offset no_signature_msg
  387.     mov    ah,9
  388.     int    21h
  389.     int    20h
  390.  
  391.  
  392. our_recv:
  393.     or    ax,ax            ;first or second call?
  394.     jne    our_recv_1        ;second -- we ignore the packet
  395.     push    cs
  396.     pop    es
  397.     mov    di,offset our_buffer + GIANT
  398. our_recv_1:
  399.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  400.  
  401.  
  402.     include    pkterr.asm
  403.     include    getnum.asm
  404.     include    getdig.asm
  405.     include    skipblk.asm
  406.     include    chrout.asm
  407.  
  408. our_buffer    label    byte
  409.  
  410. code    ends
  411.  
  412.     end    start
  413.